#include using namespace std; int stringLength(const char s[]) { int result = 0; while(s[result] != '\0') { result ++; } return result; } void stringCopy (char destination[], char source[]) { int i = 0; while(source[i] != '\0') { destination[i] = source[i]; i++; } destination[i] = '\0'; } bool sameString(char s[], char s2[]) { bool result = true; int i =-1; do { i++; char c1 = s[i]; char c2 = s2[i]; if(c1 >= 'a' && c1 <= 'z') { c1 -= 32; } if(c2 >= 'a' && c2 <= 'z') { c2 -= 32; } if(c1 != c2 ) { result = false; } } while(s[i] != '\0' && s2[i] != '\0'); return result; } void appendString(char destination[], char source[]) { int destinationIndex = stringLength(destination); int sourceIndex = 0; while(source[sourceIndex] != '\0') { destination[destinationIndex] = source[sourceIndex]; destinationIndex++; sourceIndex++; } destination[destinationIndex] = '\0'; } void prependString(char destination[], const char source[]) { int sourceLength = stringLength(source); int destinationLength = stringLength(destination); //Move destination over to make room for source for (int i = 0; i < destinationLength; i++) { destination[i + sourceLength] = destination [i]; } destination[sourceLength + destinationLength] = '\0'; for (int j = 0; j < sourceLength; j++) { destination[j] = source[j]; } } int split(char destination[][100], char source[],char separator) { int result = 0; int j = 0; destination[0][0] = '\0'; for(int i = 0; i < stringLength(source);i++) { if(source[i] != separator) { destination[result][j] = source[i]; j++; destination[result][j] = '\0'; } else { j = 0; result++; destination[result][j] = '\0'; } } //if the source is not empty if(source[0] != '\0') { result++; } return result; } int split(char destination[][100], char source[],char separator[]) { int result = 0; int j = 0; destination[0][0] = '\0'; for(int i = 0; i < stringLength(source);i++) { if(source[i] != separator) { destination[result][j] = source[i]; j++; destination[result][j] = '\0'; } else { j = 0; result++; destination[result][j] = '\0'; } } //if the source is not empty if(source[0] != '\0') { result++; } return result; } void main() { char s[100] = {'T','e','s','t'}; char s2[] = "Test Next Next Friday"; char s3[100] = "break"; char s4[100] = ",today is,the,,,day,before,spring,break,batman"; char splitResult[100][100]; int count = split(splitResult,s4,','); for(int i=0; i < count;i++) { cout << splitResult[i] << endl; } //prependString(s3,s4); //cout << s3 << endl; //if(sameString("batman", "BATMAN")) //{ // cout << "same string" << endl; //} //else //{ // cout << "different string" << endl; //} //cout << stringLength(s) << endl; //cout << stringLength(s2) << endl; //stringCopy(s3, s); //cout << s3 << endl; //cout << s << endl; //gets a single word //cin >> s; //cin.getline(s,100); //int i = 0; //while(s[i] != '\0') //{ // if(s[i] >= 'a' && s[i] <= 'z') // { // s[i] -= ' '; // } // i++; //} //cout << s; }